<?php
/**
 * Created by PhpStorm.
 * User: Hushengs
 * Date: 2017/5/4
 * Time: 14:11
 */
//平台垃圾任务处理
include dirname(dirname(dirname(__FILE__))).'/nn_logic/nl_common.func.php';
$dc = nl_get_dc(array(
    'db_policy' => NL_DB_WRITE,
    'cache_policy' => NP_KV_CACHE_TYPE_MEMCACHE
));
$time = date('Y-m-d');
$sql="select * from nns_mgtvbk_op_queue where nns_create_time <= DATE_ADD('{$time}',INTERVAL -90 day)";
$task_info = nl_query_by_db($sql,$dc->db());
$count =0;
foreach ($task_info as $task_info_one)
{
    $count++;
    if($task_info_one['nns_type']=='media'){
        $update_c2_task = "update nns_mgtvbk_c2_task set nns_status=7,nns_epg_status=100 where nns_org_id='{$task_info_one['nns_org_id']}' and nns_type='media' and nns_ref_id='{$task_info_one['nns_media_id']}'";
    }elseif($task_info_one['nns_type']=='index'){
        $update_c2_task = "update nns_mgtvbk_c2_task set nns_status=7,nns_epg_status=100 where nns_org_id='{$task_info_one['nns_org_id']}' and nns_type='index' and nns_ref_id='{$task_info_one['nns_index_id']}'";
    }elseif($task_info_one['nns_type']=='video'){
        $update_c2_task = "update nns_mgtvbk_c2_task set nns_status=7,nns_epg_status=100 where nns_org_id='{$task_info_one['nns_org_id']}' and nns_type='video' and nns_ref_id='{$task_info_one['nns_video_id']}'";
    }
    nl_execute_by_db($update_c2_task, $dc->db());
echo $count;
echo "<br/>";
    nl_execute_by_db("delete from nns_mgtvbk_op_queue where nns_id='{$task_info_one['nns_id']}'", $dc->db());
}
$sql_delete = "DELETE FROM nns_mgtvbk_c2_task WHERE nns_epg_status=100 OR nns_status=7";
$result = nl_execute_by_db($sql_delete,$dc->db());
if($result === true)
{
    echo "success";
}
